#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <istream>
#include <vector>
using ll = int64_t;

ll n;
std::vector<ll> a,b;
std::vector<std::vector<ll>> dp;

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin>>n;

    a.resize(n+1),b.resize(n+1),dp.resize(n+1,std::vector<ll>(n+1));

    for(ll i=1;i<=n;i++)std::cin>>a[i];
    for(ll i=1;i<=n;i++)std::cin>>b[i];

    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            if(std::abs(a[i]-b[j])<=4){
                dp[i][j]=dp[i-1][j-1]+1;
            }else{
                dp[i][j]=std::max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    std::cout<<dp[n][n]<<"\n";
}